/*     */ package cn.com.hongpay.client.utils;
/*     */ 
/*     */ import java.lang.management.ManagementFactory;
/*     */ import java.lang.management.RuntimeMXBean;
/*     */ import java.net.Inet4Address;
/*     */ import java.net.InetAddress;
/*     */ import java.net.NetworkInterface;
/*     */ import java.util.Enumeration;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ 
/*     */ public class CommonTools
/*     */ {
/*     */   public static String getHostAddr()
/*     */   {
/*     */     try
/*     */     {
/*  15 */       Enumeration allNetInterfaces = 
/*  16 */         NetworkInterface.getNetworkInterfaces();
/*  17 */       InetAddress ip = null;
/*  18 */       StringBuilder ipAddr = new StringBuilder();
/*  19 */       while (allNetInterfaces.hasMoreElements()) {
/*  20 */         NetworkInterface netInterface = 
/*  21 */           (NetworkInterface)allNetInterfaces
/*  21 */           .nextElement();
/*  22 */         Enumeration addresses = netInterface
/*  23 */           .getInetAddresses();
/*  24 */         while (addresses.hasMoreElements()) {
/*  25 */           ip = (InetAddress)addresses.nextElement();
/*  26 */           if ((ip == null) || (ip.isLoopbackAddress()) || 
/*  27 */             (!(ip instanceof Inet4Address))) continue;
/*  28 */           ipAddr.append(ip.getHostAddress()).append(";");
/*     */         }
/*     */       }
/*     */ 
/*  32 */       if (ipAddr.length() == 0) {
/*  33 */         return "unknown host";
/*     */       }
/*  35 */       return ipAddr.toString();
/*     */     }
/*     */     catch (Exception e) {
/*  38 */       e.printStackTrace();
/*  39 */     }return "unknown host";
/*     */   }
/*     */ 
/*     */   public static String getDomainNameFromReferer(HttpServletRequest request)
/*     */   {
/*  45 */     String referer = request.getHeader("REFERER");
/*  46 */     if (referer == null) {
/*  47 */       return null;
/*     */     }
/*  49 */     String domainName = "";
/*  50 */     int beginIndex = referer.indexOf("//") + 2;
/*  51 */     int endIndex = referer.indexOf("/", beginIndex);
/*  52 */     domainName = referer.substring(beginIndex, endIndex);
/*  53 */     return domainName;
/*     */   }
/*     */ 
/*     */   public static String getClientAddr(HttpServletRequest request) {
/*  57 */     String ip = request.getHeader("x-forwarded-for");
/*  58 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/*  59 */       ip = request.getHeader("x-real-ip");
/*     */     }
/*  61 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/*  62 */       ip = request.getHeader("Proxy-Client-IP");
/*     */     }
/*  64 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/*  65 */       ip = request.getHeader("WL-Proxy-Client-IP");
/*     */     }
/*  67 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/*  68 */       ip = request.getRemoteAddr();
/*     */     }
/*  70 */     return ip;
/*     */   }
/*     */ 
/*     */   public static byte[] hex2Ascii(byte[] in) {
/*  74 */     byte[] temp1 = new byte[1];
/*  75 */     byte[] temp2 = new byte[1];
/*  76 */     byte[] out = new byte[in.length * 2];
/*  77 */     int i = 0;
/*  78 */     for (int j = 0; i < in.length; i++) {
/*  79 */       temp1[0] = in[i];
/*  80 */       temp1[0] = (byte)(temp1[0] >>> 4);
/*  81 */       temp1[0] = (byte)(temp1[0] & 0xF);
/*  82 */       temp2[0] = in[i];
/*  83 */       temp2[0] = (byte)(temp2[0] & 0xF);
/*  84 */       if ((temp1[0] >= 0) && (temp1[0] <= 9))
/*  85 */         out[j] = (byte)(temp1[0] + 48);
/*  86 */       else if ((temp1[0] >= 10) && (temp1[0] <= 15)) {
/*  87 */         out[j] = (byte)(temp1[0] + 87);
/*     */       }
/*     */ 
/*  90 */       if ((temp2[0] >= 0) && (temp2[0] <= 9))
/*  91 */         out[(j + 1)] = (byte)(temp2[0] + 48);
/*  92 */       else if ((temp2[0] >= 10) && (temp2[0] <= 15)) {
/*  93 */         out[(j + 1)] = (byte)(temp2[0] + 87);
/*     */       }
/*  95 */       j += 2;
/*     */     }
/*  97 */     return out;
/*     */   }
/*     */ 
/*     */   public static byte[] ascii2Hex(byte[] in) {
/* 101 */     byte[] temp1 = new byte[1];
/* 102 */     byte[] temp2 = new byte[1];
/* 103 */     int i = 0;
/* 104 */     byte[] out = new byte[in.length / 2];
/* 105 */     for (int j = 0; i < in.length; j++) {
/* 106 */       temp1[0] = in[i];
/* 107 */       temp2[0] = in[(i + 1)];
/* 108 */       if ((temp1[0] >= 48) && (temp1[0] <= 57)) {
/* 109 */         int tmp53_52 = 0;
/* 110 */         byte[] tmp53_51 = temp1;
/* 111 */         tmp53_51[tmp53_52] = (byte)(tmp53_51[tmp53_52] - 48);
/* 112 */         temp1[0] = (byte)(temp1[0] << 4);
/*     */ 
/* 114 */         temp1[0] = (byte)(temp1[0] & 0xF0);
/* 115 */       } else if ((temp1[0] >= 97) && (temp1[0] <= 102)) {
/* 116 */         int tmp101_100 = 0;
/* 117 */         byte[] tmp101_99 = temp1;
/* 118 */         tmp101_99[tmp101_100] = (byte)(tmp101_99[tmp101_100] - 87);
/* 119 */         temp1[0] = (byte)(temp1[0] << 4);
/* 120 */         temp1[0] = (byte)(temp1[0] & 0xF0);
/*     */       }
/*     */ 
/* 123 */       if ((temp2[0] >= 48) && (temp2[0] <= 57)) {
/* 124 */         int tmp149_148 = 0;
/* 125 */         byte[] tmp149_146 = temp2;
/* 126 */         tmp149_146[tmp149_148] = (byte)(tmp149_146[tmp149_148] - 48);
/*     */ 
/* 128 */         temp2[0] = (byte)(temp2[0] & 0xF);
/* 129 */       } else if ((temp2[0] >= 97) && (temp2[0] <= 102)) {
/* 130 */         int tmp192_191 = 0;
/* 131 */         byte[] tmp192_189 = temp2;
/* 132 */         tmp192_189[tmp192_191] = (byte)(tmp192_189[tmp192_191] - 87);
/*     */ 
/* 134 */         temp2[0] = (byte)(temp2[0] & 0xF);
/*     */       }
/* 136 */       out[j] = (byte)(temp1[0] | temp2[0]);
/* 137 */       i += 2;
/*     */     }
/* 139 */     return out;
/*     */   }
/*     */ 
/*     */   public static String getProcessId() {
/* 143 */     String pName = ManagementFactory.getRuntimeMXBean().getName();
/* 144 */     int index = pName.indexOf('@');
/* 145 */     if (index == -1) {
/* 146 */       return "";
/*     */     }
/* 148 */     String pid = pName.substring(0, index);
/* 149 */     return pid;
/*     */   }
/*     */ }

/* Location:           F:\hongpay_client.jar
 * Qualified Name:     cn.com.hongpay.client.utils.CommonTools
 * JD-Core Version:    0.6.0
 */